<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-input v-model="search.teacherName" placeholder="教练姓名" clearable></el-input>
                    <el-input v-model="search.teacherMobile" placeholder="教练手机号码" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-plus" @click="table_add">增加</el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.teacher.salary.list" remoteSort :params="search" @selection-change="selectionChange" @dataChange="dataChange">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="账号" prop="account" width="120" align="center">
                        <template #default="scope">
                            {{ scope.row.teacher ? scope.row.teacher.account : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="姓名" prop="name" align="center">
                        <template #default="scope">
                            {{ scope.row.teacher ? scope.row.teacher.name : '' }}
                        </template>
                    </el-table-column>
                    <el-table-column label="底薪（元）" prop="basicSalary" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="体验课（元）" prop="trialCourse" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="30分钟课（元）" prop="classHour30" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="60分钟课（元）" prop="classHour60" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="120分钟课（元）" prop="classHour120" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="抗遗忘（元）" prop="forgetSalary" width="140" align="center">
                    </el-table-column>
                    <el-table-column label="更新时间" prop="updatedAt" width="150" align="center"></el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>

    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>

</template>

<script>
import saveDialog from './save'
export default {
    components: {
        saveDialog
    },
    data() {
        return {
            dialog: {
                save: false
            },
            selection: [],
            search: {
                name: null,
            }
        }
    },
    mounted() {
        
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = total - (page * perPage + index - perPage)
            })
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        // 增加
        table_add() {
            this.dialog.save = true
            this.$nextTick(() => {
                this.$refs.saveDialog.open()
            })
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
</style>
